/*
 * CallConfiguration.java
 * 
 * Created on Jul 13, 2007, 6:51:14 PM
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package asruby.runtime.methods {

import asruby.lang.RubyModule;
import asruby.parser.StaticScope;
import asruby.runtime.Arity;
import asruby.runtime.Block;
import asruby.runtime.IRubyObject;
import asruby.runtime.JumpTarget;
import asruby.runtime.ThreadContext;

/**
 *
 * @author headius
 */
public class CallConfiguration {
    //public static var FRAME_AND_SCOPE: CallConfiguration =  new CallConfiguration() {
        public  function pre(context:ThreadContext, self:IRubyObject, implementer:RubyModule, arity:Arity, name:String, 
        	args:Array, block:Block, scope:StaticScope, jumpTarget:JumpTarget):void{
            //context.preMethodFrameAndScope(implementer, name, self, args, arity.required(), block, scope, jumpTarget);
        }
        
        public  function post(context:ThreadContext):void{
            //context.postMethodFrameAndScope();
        }
        
        public  function name():String{
            return "FRAME_AND_SCOPE";
        }
    //};
 /*    public static var FRAME_ONLY: CallConfiguration =  new CallConfiguration() {
        public  function pre(context:ThreadContext, self:IRubyObject, implementer:RubyModule, arity:Arity, name:String, args:Array, block:Block, scope:StaticScope, jumpTarget:JumpTarget):void{
            context.preMethodFrameOnly(implementer, name, self, args, arity.required(), block, jumpTarget);
        }
        
        public  function post(context:ThreadContext):void{
            context.postMethodFrameOnly();
        }
        
        public  function name():String{
            return "FRAME_ONLY";
        }
    };
    public static var SCOPE_ONLY: CallConfiguration =  new CallConfiguration() {
        public  function pre(context:ThreadContext, self:IRubyObject, implementer:RubyModule, arity:Arity, name:String, args:Array, block:Block, scope:StaticScope, jumpTarget:JumpTarget):void{
            context.preMethodScopeOnly(implementer, scope);
        }
        
        public  function post(context:ThreadContext):void{
            context.postMethodScopeOnly();
        }
        
        public  function name():String{
            return "SCOPE_ONLY";
        }
    };
    public static var NO_FRAME_NO_SCOPE: CallConfiguration =  new CallConfiguration() {
        public  function pre(context:ThreadContext, self:IRubyObject, implementer:RubyModule, arity:Arity, name:String, args:Array, block:Block, scope:StaticScope, jumpTarget:JumpTarget):void{
        }
        
        public  function post(context:ThreadContext):void{
        }
        
        public  function name():String{
            return "NO_FRAME_NO_SCOPE";
        }
        
        public  function isNoop():Boolean{
            return true;
        }
    };
    public static var BACKTRACE_ONLY: CallConfiguration =  new CallConfiguration() {
        public  function pre(context:ThreadContext, self:IRubyObject, implementer:RubyModule, arity:Arity, name:String, args:Array, block:Block, scope:StaticScope, jumpTarget:JumpTarget):void{
            context.preMethodBacktraceOnly(name);
        }
        
        public  function post(context:ThreadContext):void{
            context.postMethodBacktraceOnly();
        }
        
        public  function name():String{
            return "BACKTRACE_ONLY";
        }
    };
    public static var BACKTRACE_AND_SCOPE: CallConfiguration =  new CallConfiguration() {
        public  function pre(context:ThreadContext, self:IRubyObject, implementer:RubyModule, arity:Arity, name:String, args:Array, block:Block, scope:StaticScope, jumpTarget:JumpTarget):void{
            context.preMethodBacktraceAndScope(name, implementer, scope);
        }
        
        public  function post(context:ThreadContext):void{
            context.postMethodBacktraceAndScope();
        }
        
        public  function name():String{
            return "BACKTRACE_AND_SCOPE";
        }
    }; 
    
    public static function getCallConfigByAnno(anno:JRubyMethod):CallConfiguration{
        if (anno.frame()) {
            if (anno.scope()) {
                return FRAME_AND_SCOPE;
            } else {
                return FRAME_ONLY;
            }
        } else if (anno.scope()) {
            if (anno.backtrace()) {
                return BACKTRACE_AND_SCOPE;
            } else {
                return SCOPE_ONLY;
            }
        } else if (anno.backtrace()) {
            return BACKTRACE_ONLY;
        } else {
            return NO_FRAME_NO_SCOPE;
        }
    } */
    
    public  function isNoop():Boolean{
        return false;
    }
}
}